package com.cr.admin.business.brand.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.cr.admin.business.brand.pojo.entity.Brand;
import com.cr.admin.business.brand.pojo.param.BrandAddParam;
import com.cr.admin.business.brand.pojo.param.BrandUpdateParam;
import com.cr.admin.business.brand.pojo.query.BrandQuery;
import com.cr.admin.business.brand.service.BrandService;
import com.cr.admin.business.topic.pojo.entity.Topic;
import com.cr.common.response.JsonResult;
import com.cr.common.response.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/api/bus/brand")
@Api(tags = "品牌管理")
public class BrandController {
    @Autowired
    private BrandService brandService;
    //@SaCheckPermission("bus:brand:query")
    @ApiOperation(value = "查询品牌列表")
    @GetMapping
    public JsonResult list(BrandQuery brandQuery) {
        PageData<Brand> pageData = PageData.page(brandQuery.getPageNum(), brandQuery.getPageSize(), () -> brandService.list(brandQuery));
        return JsonResult.success(pageData);
    }
    //@SaCheckPermission("bus:brand:add")
    @ApiOperation(value = "品牌专题")
    @PostMapping
    public JsonResult insert(@Validated @RequestBody BrandAddParam brandAddParam) {
        brandService.insert(brandAddParam);
        return JsonResult.success();
    }
    //@SaCheckPermission("bus:brand:edit")
    @ApiOperation(value = "修改品牌")
    @PutMapping()
    public JsonResult update(@Validated @RequestBody BrandUpdateParam brandUpdateParam) {
        brandService.updateById(brandUpdateParam);
        return JsonResult.success();
    }
    //@SaCheckPermission("bus:brand:query")
    @ApiOperation(value = "查询品牌详情")
    @GetMapping("{id}")
    public JsonResult getDetail(@PathVariable("id") Long id) {
        Brand brand = brandService.selectById(id);
        return JsonResult.success(brand);
    }
    //@SaCheckPermission("bus:brand:del")
    @ApiOperation(value = "删除品牌")
    @DeleteMapping()
    public JsonResult delete(@RequestParam(name = "ids") List<Long> ids){
        brandService.deleteByIds(ids);
        return JsonResult.success();
    }
}
